﻿@model ProductReviewsModel
@using Nop.Web.Models.Catalog;
@using Nop.Core.Domain.Catalog;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    foreach (var item in Model.Items)
    {

    }
    //title
    Html.AddTitleParts(Model.ProductName);
    Html.AddTitleParts(T("PageTitle.ProductReviews").Text);
}
<section class="product-reviews-page col-ms-12 col-xs-12 col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">
    <h1>@T("Reviews.ProductReviewsFor") <strong><a class="review-product-title" href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })">@Model.ProductName</a></strong></h1>

    @Html.Widget("productreviews_page_top")
    @if (Model.AddProductReview.SuccessfullyAdded)
    {
        <div class="result review-result">
            @Model.AddProductReview.Result
        </div>
        //+string+
        <a class="btn btn-primary return-from-review" href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })">Back</a>
    }
    else
    {

        using (Html.BeginForm())
        {
            <div class="review-container">
                @*<div class="message-error"> @Html.ValidationSummary(true)</div>*@
                @{
            string result = TempData["nop.blog.addcomment.result"] as string;
                }
                @if (!String.IsNullOrEmpty(result))
                {
                    <div class="result">@result</div>
                }
                @if (User.Identity.IsAuthenticated)
                {
                    <div class="inputs">
                        @*@Html.LabelFor(model => model.AddProductReview.Rating):*@
                        <div class="input-box review-rating" style="display:none;">
                            @T("Reviews.Fields.Rating.Bad")
                            @Html.RadioButtonFor(model => model.AddProductReview.Rating, "1")
                            @Html.RadioButtonFor(model => model.AddProductReview.Rating, "2")
                            @Html.RadioButtonFor(model => model.AddProductReview.Rating, "3")
                            @Html.RadioButtonFor(model => model.AddProductReview.Rating, "4")
                            @Html.RadioButtonFor(model => model.AddProductReview.Rating, "5")
                            @T("Reviews.Fields.Rating.Excellent")
                        </div>
                        <div class="inputs-box">
                            <span class="star-rating">
                                <input type="radio" name="rating" value="1"><i></i>
                                <input type="radio" name="rating" value="2"><i></i>
                                <input type="radio" name="rating" value="3"><i></i>
                                <input type="radio" name="rating" value="4"><i></i>
                                <input type="radio" name="rating" value="5"><i></i>
                            </span>
                        </div>

                        @*<div class="rating-stars">
                                <div class="rating-star rating-star-1"></div>
                                <div class="rating-star rating-star-2"></div>
                                <div class="rating-star rating-star-3"></div>
                                <div class="rating-star rating-star-4"></div>
                                <div class="rating-star rating-star-5"></div>
                            </div>*@
                    </div>
                    
                    <div class="inputs">
                        @*@Html.LabelFor(model => model.AddProductReview.Title):*@
                        <div class="input-box">
                            @Html.TextBoxFor(model => model.AddProductReview.Title, Model.AddProductReview.CanCurrentCustomerLeaveReview ? (object)(new { @class = "review-title form-control", @placeholder= "Review Title" }) : (object)(new { @class = "review-title form-control" }))
                        </div>
                        @Html.ValidationMessageFor(model => model.AddProductReview.Title)
                    </div>
                    <div class="inputs">
                        @*@Html.LabelFor(model => model.AddProductReview.ReviewText):*@
                        <div class="input-box">
                            @Html.TextAreaFor(model => model.AddProductReview.ReviewText, Model.AddProductReview.CanCurrentCustomerLeaveReview ? (object)(new { @class = "review-text form-control", rows="5", @placeholder="Write your review here..." }) : (object)(new { @class = "review-text form-control" }))
                        </div>
                        @Html.ValidationMessageFor(model => model.AddProductReview.ReviewText)
                    </div>

                    if (Model.AddProductReview.DisplayCaptcha)
                    {
                        <div class="captcha-box">
                            @Html.Raw(Html.GenerateCaptcha())
                        </div>
                        <div class="clear">
                        </div>
                    }
                    <div class="clear">
                    </div>
                    <div class="buttons">
                        <input type="submit" name="add-review" class="btn btn-danger button-red" value="@T("Reviews.SubmitButton")" />
                    </div>
                    <div class="review-notes">
                        By submitting a review, I agree to the following:
                        <ol>
                            <li>SpotsHUB will review your post before it is published</li>
                            <li>the content of your post does not violate the Terms &amp; Conditions of SpotsHUB</li>
                            <li>you are at least 13 years old</li>
                        </ol>
                    </div>
                }
                else
                {
                    <h4>Sorry! Only registered users can write reviews.</h4>
                        <a href="@Url.RouteUrl("Register")" class="btn btn-info sign-up-button">Sign up</a>
                        <a href="@Url.RouteUrl("Login")" class=" btn btn-info">Log In</a>
                        <a class="btn btn-primary return-from-review" href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })">Back</a>
                    

                }

            </div>
        }
    }
    @if (Model.Items.Count > 0)
    {
        <div class="clear">
        </div>
        <div class="product-review-list">
            <h2 class="review-title">
                @T("Reviews.ExistingReviews")
            </h2>
            @foreach (var review in Model.Items)
            {
                int reviewrating = review.Rating;
                float maxrating = Rating.MaxRating;
                float rating = (float)(reviewrating / maxrating) * 5;
                var ratingBase = Math.Floor(rating);
                var ratingTop = (rating - ratingBase) * 10;
                int ratingTopRound = Convert.ToInt32(ratingTop);
                var starFirst = 0;
                var starSecond = 0;
                var starThird = 0;
                var starFourth = 0;
                var starFifth = 0;
                if (ratingBase >= 0)
                {
                    if (ratingBase >= 1)
                    {
                        starFirst = 10;
                        if (ratingBase >= 2)
                        {
                            starSecond = 10;
                            if (ratingBase >= 3)
                            {
                                starThird = 10;
                                if (ratingBase >= 4)
                                {
                                    starFourth = 10;
                                    if (ratingBase >= 5)
                                    {
                                        starFifth = 10;
                                    }
                                    else
                                    {
                                        starFifth = ratingTopRound;
                                    }
                                }
                                else
                                {
                                    starFourth = ratingTopRound;
                                }
                            }
                            else
                            {
                                starThird = ratingTopRound;
                            }
                        }
                        else
                        {
                            starSecond = ratingTopRound;
                        }
                    }
                    else
                    {
                        starFirst = ratingTopRound;
                    }
                }

                int ratingPercent = review.Rating * 20;
                <div class="product-review-item">
                    <div class="product-rating" title="@review.Rating">
                        <div class="rating-stars">
                            <div class="star-base"><div class="star-top rate-@starFirst"></div></div>
                            <div class="star-base"><div class="star-top rate-@starSecond"></div></div>
                            <div class="star-base"><div class="star-top rate-@starThird"></div></div>
                            <div class="star-base"><div class="star-top rate-@starFourth"></div></div>
                            <div class="star-base"><div class="star-top rate-@starFifth"></div></div>
                        </div>
                    </div>
                    <h3 class="review-title">
                        @review.Title
                    </h3>
                    <div class="review-info">
                        @if (review.AllowViewingProfiles)
                        {
                            <a href="@Url.RouteUrl("CustomerProfile", new { id = review.CustomerId })">@(review.CustomerName)</a>
                        }
                        else
                        {
                            @review.CustomerName
                        }
                        <span class="separator">|</span>
                        @review.WrittenOnStr
                    </div>
                    <div class="product-review-box">
                        <div class="rating">
                            <div style="width: @(ratingPercent)%">
                            </div>
                        </div>
                    </div>
                    <div class="clear">
                    </div>
                    <div class="review-text">
                        @Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(review.ReviewText, false, true, false, false, false, false))
                    </div>
                    <div class="clear">
                    </div>

                    @Html.Partial("_ProductReviewHelpfulness", review.Helpfulness, new ViewDataDictionary())
                    @Html.Widget("productreviews_page_inside_review")
                </div>
            }
        </div>
    }
    @Html.Widget("productreviews_page_bottom")
    <script>
        $('.forms-box .rating-star').mouseenter(function () {
            $('.forms-box .rating-star').removeClass('hover');
            $(this).prevAll('.rating-star').andSelf().addClass('hover');
        }).click(function () {
            $('.forms-box .rating-star').removeClass('click');
            $(this).prevAll('.rating-star').andSelf().addClass('click');
            $('.forms-box input#AddProductReview_Rating').eq($('.forms-box .rating-star').index($(this))).attr("checked", "checked");
        });

        $('.forms-box .rating-stars').mouseleave(function () {
            $('.forms-box .rating-star').removeClass('hover');
        });
    </script>
</section>



<div class="clear"></div>

